package com.myCinema.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.myCinema.dao.EmployeeDao;
import com.myCinema.dao.HibernateUtil;
import com.myCinema.entity.Employee;

public class EmployeeDaoImpl implements EmployeeDao {

	public void add(Employee emp) {
		Session sess = null;
		try{
			sess = HibernateUtil.openSession();
			Transaction tx = sess.beginTransaction();
			sess.save(emp);
			tx.commit();
		}finally{
			sess.close();
		}
	}

	public List<Employee> getEmployee(int deptId) {
		Session sess = null;
		try{
			sess = HibernateUtil.openSession();
			Query query = sess.createQuery("from Employee where deptId = ?");
			query.setInteger(0, deptId);
			return query.list();
		}finally{
			sess.close();
		}
	}

}
